<?php
/* SVN FILE: $Id: adminSettings.php 256 2010-01-05 01:09:10Z supersmashbrothers $ */
/**
* ibMarket 2
* IP.Board 3.0
* ibMarket Transfer Settings
*
* @author $Author: supersmashbrothers $
* @copyright $Copyright$
* @version $Revision: 256 $
* @lastrevision $Date: 2010-01-05 01:09:10 +0000 (Tue, 05 Jan 2010) $
* @modifiedby $LastChangedBy: supersmashbrothers $
* @lastmodified $LastChangedDate: 2010-01-05 01:09:10 +0000 (Tue, 05 Jan 2010) $
* @filesource $URL: http://ipb-ibmarket.googlecode.com/svn/ibmarket2/trunk/admin/applications_addon/other/ibmarket/plugins/transfer/adminSettings.php $
*/

class admin_settings__transfer extends admin_settings
{
	/**
	 * The settings form a person see
	 *
	 * @access	public
	 * @return	string	The settings HTML
	 */
	public function settingsForm(array $pluginInfo)
	{
		$this->registry->getClass('class_localization')->loadLanguageFile( array( 'transfer_transfer' ) );
		
		$settings = unserialize($pluginInfo['plugin_config']);
		$settings['send_pm'] = isset($settings['allow_anon']) ? $settings['allow_anon'] : 1;
		$settings['send_pm'] = isset($settings['send_pm']) ? $settings['send_pm'] : 1;
		$settings['subject'] = isset($settings['subject']) ? $settings['subject'] : "Transferring";
		$settings['message'] = isset($settings['message']) ? $settings['message'] : <<<EOF
{member_name_to},

I have sent you:[list]
[*]{currency_name} {money_amount}
[/list]{item_list}

Sincerly,
{member_name_from}

[b]This is an automated message[/b]
EOF;
		$settings['anon_sub'] = isset($settings['anon_sub']) ? $settings['anon_sub'] : "Anonymous Transferring";
		$settings['anon_msg'] = isset($settings['anon_msg']) ? $settings['anon_msg'] : <<<EOF
{member_name_to},

I have sent you:[list]
[*]{currency_name} {money_amount}
[/list]{item_list}

Anonymous

[b]This is an automated message[/b]
EOF;
		if ( IPSText::getTextClass('editor')->method == 'rte' )
		{
			$_message = IPSText::getTextClass('bbcode')->convertForRTE( $settings['message'] );
		}
		else
		{
			$_message = IPSText::getTextClass('bbcode')->preEditParse( $settings['message'] );
		}
		if ( IPSText::getTextClass('editor')->method == 'rte' )
		{
			$_anon_msg = IPSText::getTextClass('bbcode')->convertForRTE( $settings['anon_msg'] );
		}
		else
		{
			$_anon_msg = IPSText::getTextClass('bbcode')->preEditParse( $settings['anon_msg'] );
		}
		$anon = array(
						array(0, $this->lang->words['setting_anon_0']),
						array(1, $this->lang->words['setting_anon_1']),
						array(2, $this->lang->words['setting_anon_2']),
					);
		$PMs = array(
						array(0, $this->lang->words['setting_send_0']),
						array(1, $this->lang->words['setting_send_1']),
						array(2, $this->lang->words['setting_send_2']),
					);
		$anonymous = ipsRegistry::getClass('output')->formDropdown('allow_anon', $anon ,$settings['allow_anon']);
		$sendPM = ipsRegistry::getClass('output')->formDropdown('send_pm', $PMs ,$settings['send_pm']);
		$subject = ipsRegistry::getClass('output')->formInput('subject', $settings['subject']);
		$message = IPSText::getTextClass('editor')->showEditor( $_message, 'message' );
		$anon_sub = ipsRegistry::getClass('output')->formInput('anon_sub', $settings['anon_sub']);
		$anon_msg = IPSText::getTextClass('editor')->showEditor( $_anon_msg, 'anon_msg' );
		return <<<EOF
			<li>
				<label>
					{$this->lang->words['setting_anonymous']}
					<span class="desctext">{$this->lang->words['setting_anonymous_desc']}</span>
				</label>
				{$anonymous}
			</li>
			<li>
				<label>{$this->lang->words['setting_send_message']}</label>
				{$sendPM}
			</li>
			<li>
				<label>{$this->lang->words['setting_message_subject']}</label>
				{$subject}
			</li>
			<li>
				<label>{$this->lang->words['setting_message_message']}</label>
				<br />
				{$message}
			</li>
			<li>
				<label>
					{$this->lang->words['setting_anon_subject']}
					<span class="desctext">{$this->lang->words['setting_anon_desc']}</span>
				</label>
				{$anon_sub}
			</li>
			<li>
				<label style="display: block">
					{$this->lang->words['setting_anon_message']}
					<span class="desctext">{$this->lang->words['setting_anon_desc']}</span>
				</label>
				<br /><br />
				{$anon_msg}
			</li>
			<li>
				<label>{$this->lang->words['tags_for_messages']}</label>
				<div style='display: inline-block'>
					{member_name_from} = {$this->lang->words['tag_sender']}
					<br />
					{member_name_to} = {$this->lang->words['tag_receiver']}
					<br />
					{money_amount} = {$this->lang->words['tag_money']}
					<br />
					{currency_name} = {$this->lang->words['tag_currency']}
					<br />
					{item_list} = {$this->lang->words['tag_item_list']}
					<br />
					{item_names} = {$this->lang->words['tag_item_series']}
				</div>
			</li>

EOF;
	}
	
	/**
	 * Saving the settings to a plugin
	 *
	 * @access	public
	 * @return	void
	 */
	public function settingsSave(array &$pluginInfo)
	{
		$setting = array();
		$setting['send_pm'] = min(max(intval($this->request['send_pm']),0),2);
		$setting['subject'] = $this->request['subject'];
		$setting['message'] = IPSText::getTextClass('bbcode')->preEditParse(IPSText::getTextClass('bbcode')->preDbParse(IPSText::getTextClass('editor')->processRawPost('message')));
		$setting['allow_anon'] = min(max(intval($this->ipsclass->input['allow_anon']),0),2);
		$setting['anon_sub'] = $this->request['anon_sub'];
		$setting['anon_msg'] = IPSText::getTextClass('bbcode')->preEditParse(IPSText::getTextClass('bbcode')->preDbParse(IPSText::getTextClass('editor')->processRawPost('anon_msg')));
		
		if($setting['send_pm'])
		{
			if(!$setting['subject'])
			{
				$this->registry->output->showError( $this->lang->words['setting_need_subject'] );
			}
			if($setting['allow_anon'])
			{
				if(!$setting['anon_sub'])
				{
					$this->registry->output->showError( $this->lang->words['setting_need_anon_sub'] );
				}
			}
		}
		
		$pluginInfo['plugin_config'] = serialize($setting);
	}
}